<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>blob.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_testing_fs_blob.js.html">blob.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Mock blob object.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.testing.fs.Blob&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.crypt.base64&#39;);
<a name="line23"></a>
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>/**
<a name="line27"></a> * A mock Blob object. The data is stored as a string.
<a name="line28"></a> *
<a name="line29"></a> * @param {string=} opt_data The string data encapsulated by the blob.
<a name="line30"></a> * @param {string=} opt_type The mime type of the blob.
<a name="line31"></a> * @constructor
<a name="line32"></a> */
<a name="line33"></a>goog.testing.fs.Blob = function(opt_data, opt_type) {
<a name="line34"></a>  /**
<a name="line35"></a>   * @see http://www.w3.org/TR/FileAPI/#dfn-type
<a name="line36"></a>   * @type {string}
<a name="line37"></a>   */
<a name="line38"></a>  this.type = opt_type || &#39;&#39;;
<a name="line39"></a>
<a name="line40"></a>  this.setDataInternal(opt_data || &#39;&#39;);
<a name="line41"></a>};
<a name="line42"></a>
<a name="line43"></a>
<a name="line44"></a>/**
<a name="line45"></a> * The string data encapsulated by the blob.
<a name="line46"></a> * @type {string}
<a name="line47"></a> * @private
<a name="line48"></a> */
<a name="line49"></a>goog.testing.fs.Blob.prototype.data_;
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>/**
<a name="line53"></a> * @see http://www.w3.org/TR/FileAPI/#dfn-size
<a name="line54"></a> * @type {number}
<a name="line55"></a> */
<a name="line56"></a>goog.testing.fs.Blob.prototype.size;
<a name="line57"></a>
<a name="line58"></a>
<a name="line59"></a>/**
<a name="line60"></a> * @see http://www.w3.org/TR/FileAPI/#dfn-slice
<a name="line61"></a> * @param {number} start The start byte offset.
<a name="line62"></a> * @param {number} length The number of bytes to slice.
<a name="line63"></a> * @param {string=} opt_contentType The type of the resulting Blob.
<a name="line64"></a> * @return {!goog.testing.fs.Blob} The result of the slice operation.
<a name="line65"></a> */
<a name="line66"></a>goog.testing.fs.Blob.prototype.slice = function(
<a name="line67"></a>    start, length, opt_contentType) {
<a name="line68"></a>  start = Math.max(0, start);
<a name="line69"></a>  return new goog.testing.fs.Blob(
<a name="line70"></a>      this.data_.substring(start, start + Math.max(length, 0)),
<a name="line71"></a>      opt_contentType);
<a name="line72"></a>};
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/**
<a name="line76"></a> * @return {string} The string data encapsulated by the blob.
<a name="line77"></a> * @override
<a name="line78"></a> */
<a name="line79"></a>goog.testing.fs.Blob.prototype.toString = function() {
<a name="line80"></a>  return this.data_;
<a name="line81"></a>};
<a name="line82"></a>
<a name="line83"></a>
<a name="line84"></a>/**
<a name="line85"></a> * @return {ArrayBuffer} The string data encapsulated by the blob as an
<a name="line86"></a> *     ArrayBuffer.
<a name="line87"></a> */
<a name="line88"></a>goog.testing.fs.Blob.prototype.toArrayBuffer = function() {
<a name="line89"></a>  var buf = new ArrayBuffer(this.data_.length * 2);
<a name="line90"></a>  var arr = new Uint16Array(buf);
<a name="line91"></a>  for (var i = 0; i &lt; this.data_.length; i++) {
<a name="line92"></a>    arr[i] = this.data_.charCodeAt(i);
<a name="line93"></a>  }
<a name="line94"></a>  return buf;
<a name="line95"></a>};
<a name="line96"></a>
<a name="line97"></a>
<a name="line98"></a>/**
<a name="line99"></a> * @return {string} The string data encapsulated by the blob as a data: URI.
<a name="line100"></a> */
<a name="line101"></a>goog.testing.fs.Blob.prototype.toDataUrl = function() {
<a name="line102"></a>  return &#39;data:&#39; + this.type + &#39;;base64,&#39; +
<a name="line103"></a>      goog.crypt.base64.encodeString(this.data_);
<a name="line104"></a>};
<a name="line105"></a>
<a name="line106"></a>
<a name="line107"></a>/**
<a name="line108"></a> * Sets the internal contents of the blob. This should only be called by other
<a name="line109"></a> * functions inside the {@code goog.testing.fs} namespace.
<a name="line110"></a> *
<a name="line111"></a> * @param {string} data The data for this Blob.
<a name="line112"></a> */
<a name="line113"></a>goog.testing.fs.Blob.prototype.setDataInternal = function(data) {
<a name="line114"></a>  this.data_ = data;
<a name="line115"></a>  this.size = data.length;
<a name="line116"></a>};
</pre>


</body>
</html>
